//
//  AppDelegate.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/6/23.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        //设置app颜色
        setAppColor()
        
        //设置window 初始化
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        //设置window的背景颜色
        window?.backgroundColor = UIColor.whiteColor()
        
        //设置根控制器
        setupRootVC()
        
        //设置window成为主窗口并显示
        window?.makeKeyAndVisible()
        
        //接收通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "switchRootVcNoti:", name: SwitchRootVcNoti, object: nil)
        
        
        return true
    }
    
    //设置app控件的颜色
    func setAppColor(){
        
        //tintColor 设置控件颜色
        UITabBar.appearance().tintColor = ThemeColor
        
        UINavigationBar.appearance().tintColor = ThemeColor
    }
    //设置根控制器
    func setupRootVC(){
        
        if LLUserAccountTools.sharedTools.isLogin {
            
            window?.rootViewController = LLWelcomeViewControllers()
        }else{
            
            window?.rootViewController = LLMainTabBarController()
        }
    }
    
    
    //通知切换根控制器
    func switchRootVcNoti(noti:NSNotification){
        
        if noti.object == nil {
            
            window?.rootViewController = LLWelcomeViewControllers()
        }else{
            
            window?.rootViewController = LLMainTabBarController()
        }
    }

    func  applicationDidEnterBackground(application: UIApplication) {
        LLStatusDAL.deleteCache()
    }

}

